import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'

import {resolve} from "path";

// https://vite.dev/config/
export default defineConfig(({mode}) => {
    const env = loadEnv(mode, process.cwd(), '')
    return {
        base: '/',
        server: {
            hmr: {overlay: false},
            open: false,
            host: true,
            https: false,
            proxy: {
                [env.BASE_URL]: {
                    target: env.PROXY_URL,
                    changeOrigin: true
                }
            }
        },
        resolve: {
            alias: {
                '@': resolve(__dirname, 'src'),
            }
        },
        plugins: [
            vue(),
            vueDevTools(),
            AutoImport({
                imports: ['vue', '@vueuse/core', 'vue-router', 'pinia'],
                resolvers: [ElementPlusResolver()],
                // dts: true, // 生成 auto-imports.d.ts 文件
            }),
            Components({
                resolvers: [ElementPlusResolver()],
                // dts: true,  // 生成 components.d.ts 文件
            }),
        ]
    }
})
